package com.atty.dms.dao.mapper;

import com.atty.dms.dao.entity.DormitoryStudentDO;
import com.atty.dms.dto.resp.DormitoryStudentRespDTO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * ClassName:DormitoryStudentMapper
 * Package:com.atty.dms.dao.mapper
 * Description:
 *
 * @Author:tony
 * @Create :2025/4/22 9:29
 * @Version :1.0
 */
public interface DormitoryStudentMapper extends BaseMapper<DormitoryStudentDO> {
        /**
         * 根据宿舍ID查询学生id列表
         *
         * @param dormitoryId 宿舍ID
         * @return 学生id列表
         */
        @Select("SELECT student_id FROM dormitories_students WHERE dormitory_id = #{dormitoryId}")
        List<Long> getStudentIdsByDormitoryId(Long dormitoryId);

        /**
         * 更新学生宿舍信息
         * @param studentId
         * @param newDormitoryId
         * @return
         */
        @Update("UPDATE dormitories_students SET dormitory_id = #{newDormitoryId} WHERE student_id = #{studentId}")
        int updateDormitoryForStudent(@Param("studentId") Long studentId, @Param("newDormitoryId") Long newDormitoryId);

        @Delete("DELETE FROM dormitories_students WHERE student_id = #{studentId}")
        int deleteDormitoryStudent(@Param("studentId") Long studentId);

}
